home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / dviware / dvitovdu32 / src / pascal / vis603vdu.p < prev    next >
Text File  |  1991-11-10  |  8KB  |  248 lines

  1. (* VDU routines for a VIS603 terminal, by David Beard. *)
  2.  
  3. #include 'globals.h';
  4. #include 'screenio.h';
  5. #include 'vdu.h';
  6. #include 'tek4010vdu.h';
  7.  
  8. VAR cursrow, curscol : INTEGER;   (* ShowChar remembers cursor location *)
  9.     textmode : BOOLEAN;           (* are we in VT200 mode? *)
  10.  
  11. (******************************************************************************)
  12.  
  13. PROCEDURE StartText;
  14.  
  15. (* We are about to draw text in dialogue region. *)
  16.  
  17. BEGIN
  18. WriteChar(CAN);
  19. textmode := true;
  20. END; (* StartText *)
  21.  
  22. (******************************************************************************)
  23.  
  24. PROCEDURE MoveAbs (row, col : INTEGER);
  25.  
  26. (* Move cursor to given screen position. *)
  27.  
  28. BEGIN
  29. WriteChar(ESC); WriteChar('[');
  30. WriteInt(row);
  31. WriteChar(';');
  32. WriteInt(col);
  33. WriteChar('H');
  34. END; (* MoveAbs *)
  35.  
  36. (******************************************************************************)
  37.  
  38. PROCEDURE MoveToTextLine (line : INTEGER);
  39.  
  40. (* Move current position to start of given line. *)
  41.  
  42. BEGIN
  43. WriteChar(CAN);
  44. textmode := true;
  45. MoveAbs(line,1);
  46. END; (* MoveToTextLine *)
  47.  
  48. (******************************************************************************)
  49.  
  50. PROCEDURE ClearTextLine (line : INTEGER);
  51.  
  52. (* Erase given line; note that DVItoVDU does not assume anything about the
  53.    current position at the end of this routine.
  54. *)
  55.  
  56. BEGIN
  57. WriteChar(CAN);
  58. textmode := true;
  59. MoveAbs(line,1);
  60. WriteChar(ESC);
  61. WriteString('[K');   (* erase to end of line *)
  62. END; (* ClearTextLine *)
  63.  
  64. (******************************************************************************)
  65.  
  66. PROCEDURE ClearScreen;
  67.  
  68. BEGIN
  69. WriteChar(CAN);
  70. textmode := true;
  71. WriteChar(ESC);
  72. WriteString('[2J');   (* erase all alphanumerics *)
  73. TEK4010ClearScreen;
  74. textmode := false;
  75. END; (* ClearScreen *)
  76.  
  77. (******************************************************************************)
  78.  
  79. PROCEDURE StartGraphics;
  80.  
  81. (* We are about to draw in window region. *)
  82.  
  83. BEGIN
  84. TEK4010StartGraphics;
  85. textmode := false;
  86. cursrow := 0;
  87. END; (* StartGraphics *)
  88.  
  89. (******************************************************************************)
  90.  
  91. PROCEDURE LoadFont (fontname : string;
  92.                     fontsize : INTEGER;
  93.                     mag, hscale, vscale : REAL);
  94.  
  95. BEGIN
  96. TEK4010LoadFont(fontname,fontsize,mag,hscale,vscale);
  97. textmode := false;
  98. END; (* LoadFont *)
  99.  
  100. (******************************************************************************)
  101.  
  102. PROCEDURE ShowChar (screenh, screenv : INTEGER;
  103.                     ch : CHAR);
  104.  
  105. (* We use VT200 text mode because it is much faster. *)
  106.  
  107. VAR amount : INTEGER;
  108.  
  109. BEGIN
  110. (* first translate DVItoVDU coordinates into actual screen location *)
  111. if not textmode then
  112.    begin
  113.    WriteChar(CAN);
  114.    textmode := true
  115.    end;
  116. screenh := trunc (screenh * 132 / 1024);
  117. screenv := trunc (screenv * 24 / (780-35));
  118.  
  119. screenh := screenh + 1;
  120. screenv := screenv + 1;
  121. IF cursrow = screenv THEN BEGIN
  122.    (* The cursor is on the same line as in previous ShowChar call so we only
  123.       need to move left or right, and probably just a small amount (if at all).
  124.    *)
  125.    IF screenh = curscol THEN       (* cursor in correct location *)
  126.       curscol := curscol + 1       (* cursor will move right when ch written *)
  127.    ELSE IF screenh < curscol THEN BEGIN      (* move cursor left *)
  128.       amount := curscol - screenh;
  129.       WriteChar(ESC); WriteChar('[');
  130.       IF amount > 1 THEN BEGIN               (* default is 1 col *)
  131.          WriteInt(amount);
  132.          curscol := curscol - (amount-1);    (* no need if amount = 1 *)
  133.       END;
  134.       WriteChar('D');
  135.    END
  136.    ELSE BEGIN                                (* move cursor right *)
  137.       amount := screenh - curscol;
  138.       WriteChar(ESC); WriteChar('[');
  139.       IF amount > 1 THEN WriteInt(amount);   (* default is 1 col *)
  140.       curscol := curscol + (amount+1);
  141.       WriteChar('C');
  142.    END;
  143. END
  144. ELSE BEGIN                         (* cursrow undefined or ch on a new line *)
  145.    MoveAbs(screenv,screenh);
  146.    cursrow := screenv;
  147.    curscol := screenh + 1;         (* cursor will move right when ch written *)
  148. END;
  149. IF screenh = windowwd THEN         (* ch will be written at right edge *)
  150.    cursrow := 0;                   (* so avoid auto wrap next time around *)
  151. WriteChar(TeXtoASCII[ch]);
  152. END; (* ShowChar *)
  153.  
  154. (******************************************************************************)
  155.  
  156. PROCEDURE ShowRectangle (screenh, screenv,          (* top left pixel *)
  157.                          width, height : INTEGER;   (* size of rectangle *)
  158.                          ch : CHAR);                (* black pixel *)
  159.  
  160. (* Display the given rectangle. *)
  161.  
  162. VAR pos : INTEGER;
  163.  
  164. BEGIN
  165. textmode := false;
  166. IF height = 1 THEN BEGIN            (* show row vector *)
  167.    pos := 779 - screenv;
  168.    WriteChar(GS);
  169.    SendXY(screenh,pos);             (* move cursor to start of row *)
  170.    SendXY(screenh+width-1,pos);     (* draw vector to end of row *)
  171. END
  172. ELSE IF width = 1 THEN BEGIN        (* show column vector *)
  173.    pos := 779 - screenv;
  174.    WriteChar(GS);
  175.    SendXY(screenh,pos);             (* move cursor to start of column *)
  176.    SendXY(screenh,pos-height+1);    (* draw vector to end of column *)
  177. END
  178. ELSE BEGIN
  179.    (* assume height and width > 1; draw and fill rectangle *)
  180.    pos := 779 - (screenv+height-1);
  181.    WriteChar(ESC);         WriteChar('/');
  182.    WriteInt(screenh);      WriteChar(';');   (* left *)
  183.    WriteInt(pos);          WriteChar(';');   (* bottom *)
  184.    WriteInt(width-1);      WriteChar(';');
  185.    WriteInt(height+1);     WriteChar('y');
  186.    (* Note that there are a few problems with this command:
  187.       - we need to subtract 1 from width.  While this prevents exceeding the
  188.         right edge (reason unknown), it causes missing pixel columns.
  189.       - we need to ADD 1 to height to avoid missing pixel rows.
  190.       - the smallest rectangle drawn is 2 by 2.
  191.       - the new cursor position is undefined.
  192.       IS THIS TRUE FOR VIS 603???
  193.       These funnies are outweighed by the improved efficiency in drawing large
  194.       rectangles.
  195.    *)
  196.    havesentxy := FALSE;   (* need to re-synch cursor position *)
  197. END;
  198. END; (* ShowRectangle *)
  199.  
  200. (******************************************************************************)
  201.  
  202. PROCEDURE ResetVDU;
  203.  
  204. BEGIN
  205. WriteChar(ESC); WriteString('[?50h');   (* 80 COL ITAG + graphics *)
  206. WriteChar(CAN);
  207. textmode := true;
  208. END; (* ResetVDU *)
  209.  
  210. (******************************************************************************)
  211.  
  212. PROCEDURE InitVDU;
  213.  
  214. (* The dialog region will be the top 4 text lines in VT200 mode:
  215.       Line 1 = DVI status line,
  216.       Line 2 = window status line,
  217.       Line 3 = message line,
  218.       Line 4 = command line.
  219.    The window region will be text lines 5 to 24 in VT200 mode.
  220. *)
  221.  
  222. BEGIN
  223. InitTEK4010VDU;
  224. DVIstatusl    := 1;      (* DVItoVDU assumes top text line = 1 *)
  225. windowstatusl := 2;
  226. messagel      := 3;
  227. commandl      := 4;
  228. bottoml       := 24;     (* also number of text lines on screen *)
  229. (* The above values assume the VIS603 is in VT200 mode;
  230.    the following values assume it is emulating a Tektronix 4010.
  231.    Note that windowv must be given a value using DVItoVDU's coordinate scheme
  232.    where top left pixel is (0,0).
  233. *)
  234. windowv  := 125;         (* approx. height in TEK4010 pixels of 4 text lines
  235.                             i.e. ~ 4 * 780/25 *)
  236. windowh  := 0;
  237. windowht := 780-windowv-35;   (* avoid drawing in status line *)
  238. windowwd := 1024;
  239.  
  240. WriteChar(GS);
  241. WriteChar(ESC);
  242. WriteChar('@');          (* solid fill for rectangular draw and fill *)
  243. WriteChar(ESC);
  244. WriteString('[?40h');    (* 132 COL ITAG + graphics *)
  245. WriteChar(CAN);
  246. textmode := true;
  247. END; (* InitVDU *)
  248.